﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LowLevelGraphics.Filter.Frequency
{
    /// <summary>
    /// gives the inverse distance transform of image, returning the result as a binary image.
    /// This means to reconstruct a binary image from a skeleton
    /// %# get binary image
    /// BW = ~imread('http://img546.imageshack.us/img546/3154/hand2.png');
    /// 
    /// %# SkeletonTransform[]
    /// skel = bwmorph(BW,'skel',Inf);
    /// DD = double(bwdist(~BW));
    /// D = zeros(size(DD));
    /// D(skel) = DD(skel)
    /// 
    /// %# zero-centered unit circle
    /// t = linspace(0,2*pi,50);
    /// ct = cos(t);
    /// st = sin(t);
    /// 
    /// %# InverseDistanceTransform[] : union of all disks centered around each
    /// %# pixel of the distance transform, taking pixel values as radius
    /// [r c] = size(D);
    /// BW2 = false(r,c);
    /// for j=1:c
    ///     for i=1:r
    ///         if D(i,j)==0, continue; end
    ///             mask = poly2mask(D(i,j).*st + j, D(i,j).*ct + i, r, c);
    ///                 BW2(mask) = true;
    ///     end
    /// end
    /// 
    /// %# plot
    /// figure
    /// subplot(131), imshow(BW), title('original')
    /// subplot(132), imshow(D,[]), title('Skeleton+DistanceTransform')
    /// subplot(133), imshow(BW2), title('InverseDistanceTransform')
    /// </summary>
    public class InverseDistanceTransform : BaseImageFilter
    {
        /// <summary>
        /// 
        /// </summary>
        public InverseDistanceTransform()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_inverseDistanceTransform"></param>
        internal InverseDistanceTransform(InverseDistanceTransform _inverseDistanceTransform)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            return base.Execute(_bitmap);
        }

        /// <summary>
        /// used to clone
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new InverseDistanceTransform(this);
        }
    }
}
